<template>
	<view class="main">
		<view>
			<view class="matching">匹配<text>{{toUser.user}}</text>咨询陪护人员中</view>
			<view class="time">请等待<text>{{timeData}}</text>s</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				timeData : 60,
				toData : 0,
				toUser : {},
				countdown : ''
			};
		},
		onUnload(){
			// #ifndef H5
			uni.showShareMenu({
				showShareItems : ['qq', 'qzone', 'wechatFriends', 'wechatMoment']	
			});
			// #endif
			clearInterval(this.countdown);
		},
		onLoad() {
			const that = this;
			this.toUser = uni.getStorageSync('toUser');
			this.countdown = setInterval(() => {
				console.log( 'toUser', this.toUser );   
				this.timeData--;
				this.toData ++ ;
				// 走后端访问。专家是否就绪.
				if( this.toData == 10 ){
					this.toData = 0 ;
					
					
					this.$apiW.isJiuXu({userId : this.toUser.userId}).then( res => {
						if( res.data == 1 ){
							clearInterval(that.countdown);
							uni.redirectTo({
								url: '/pages/tim/room'
							});
							let userInfo = uni.getStorageSync('userInfo');
							// 扣除积分同时更新积分。 String userId,String userSig,int i
							that.$apiW.jianJiFen({userId : userInfo.userId , userSig : userInfo.userSig , i : that.$tools.commons.getConfig('integralMin')}).then( res => {
								// 更新积分
								uni.setStorageSync('userInfo',res.data);
								console.log(res.data);
							})
						}
						//
					});
				}
				// 换专家处理，继续跳转该页面.
				if (this.timeData < 0) {
					clearInterval(that.countdown);
					uni.showToast({
						title: '切换其他专家中,请稍等',
						icon: "none",
						duration : 2000
					})
					this.$tools.commons.help('2');
				}
			}, 1000);
		}
		
	}
</script>

<style lang="scss" scoped>
	.main{
		height: 100%;
		background-image: url(//jihe2.oss-cn-beijing.aliyuncs.com/xinli/bg.jpg);
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 44upx;
		view{
			width: 100%;
			text-align: center;
		}
		.matching{
			text{
				color: #df5451;
			}
		}
		.time{
			margin-top: 24upx;
			text{
				background-color: #df5451;
				color: rgb(255, 255, 1);
				padding: 10upx;
				margin: 0 10upx;
			}
		}
	}
</style>
